package info.demo.view;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;

public class BufferedResponseWrapper extends HttpServletResponseWrapper {

	PrintWriter pw = null;
	ByteArrayOutputStream baos = null;
	String priCharSet;

	public BufferedResponseWrapper(HttpServletResponse response, String charSet) {
		super(response);
		baos = new ByteArrayOutputStream();
		pw = new PrintWriter(baos);
		this.priCharSet = charSet;
	}

	public PrintWriter getWriter() throws IOException {
		return pw;
	}

	public String getOutput() throws Exception {
		pw.flush();
		pw.close();
		return baos.toString(priCharSet);
	}
}
